var db = null;

function openDb(){

    db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    
    console.log("dbconnection.js >>db succ");
    
   /*
     db.transaction(queryDB, errorCB);
     db.transaction(function(tx) {
                    tx.executeSql();
     });
     // deleteProperty(db);
  */
    
    
    db.transaction(populateDB, errordCB, successdCB);

    
}

function populateDB(tx) {
   
    tx.executeSql("DELETE FROM Payers WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM AdvanceDirectives WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM FunctionalStatus WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM FamilyHistory WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Problems WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM SocialHistory WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Alerts WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Medications WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Immunizations WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM VitalSigns WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Results WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Procedures WHERE CCRDataObjectID != '' ");
    tx.executeSql("DELETE FROM Encounters WHERE CCRDataObjectID != '' ");
    
    
    
    
    
    tx.executeSql("DELETE FROM dialysis_Procedures");
 
    
    console.log("dbconnection.js >> delete from 13 ccr section **********************************************");
    
    //tx.executeSql('DELETE FROM Agent_FunctionalStatus');        
    console.log("dbconnection.js >>^^^^^^^^^^^^^       DELETE FROM Agent_FunctionalStatus      " );
}

function successdCB() {
    console.log("dbconnection.js delete >>success processing SQL!");
}

function errordCB(err) {
    console.log("dbconnection.js delete >>Error processing SQL: "+err.message);
    
}


function successCB() {
    console.log("dbconnection.js >>success processing SQL!");
}

function errorCB(err) {
    console.log("dbconnection.js >>Error processing SQL: "+err.message);
    
}


function ccrdb(tx) {
    tx.executeSql('select updatedate from ccr', [], ccrlist, errorCB);
}

function AdvanceDirectivesDB(tx) {
    tx.executeSql('select Type,Description,Datetime_Type,Datetime_Value,Status,Actor_Id,Actor_Role,CCRDataObjectID from AdvanceDirectives', [], AdvanceDirectiveslist, errorCB);
}
function PayersDB(tx) {
    tx.executeSql('select Type,Question_Name,Question_Co,Datetime_Value,Subscriber,PaymentProvider,Question_No,Actor_Id,Actor_Role,CCRDataObjectID from Payers', [], Payerslist, errorCB);
}
function FunctionalStatusDB(tx) {
    tx.executeSql('select Problem_Desc,Type,Description,Testresult_Value,Testresult_Unit,Problem_Actorid,Problem_Actorrole,Datetime_type,Status,Actor_Id,Actor_Role,Datetime_Value,CCRDataObjectID from FunctionalStatus', [], FunctionalStatuslist, errorCB);
}
function ProblemsDB(tx) {
    tx.executeSql('select Description,Type,Status,Datetime_Type,Actor_Id,Actor_Role,Datetime_Value,CCRDataObjectID from Problems', [], Problemslist, errorCB);
}
function FamilyHistoryDB(tx) {
    tx.executeSql('select Description,Status,Exactdatetime,Type,Familymember_Actorrole,Familymember_Actorid,Healthstatus,Problem_Desc,Actor_Id,Actor_Role,CCRDataObjectID from FamilyHistory', [], FamilyHistorylist, errorCB);
}
function SocialHistoryDB(tx) {
    tx.executeSql('select Description,Type,Datetime_Type,Status,Datetime_Value,Actor_Id,Actor_Role,CCRDataObjectID from SocialHistory', [], SocialHistorylist, errorCB);
}
function AlertsDB(tx) {
    tx.executeSql('select Description,Type,Status,Actor_Id,Actor_Role,Datetime_Type,Severity,Reaction_Desc,Datetime_Value,CCRDataObjectID from Alerts', [], Alertslist, errorCB);
}
function MedicationsDB(tx) {
    tx.executeSql('select Productname,Type,Status,Route,Frequency,Quantity,Manufacturer,Instruction,Datetime_Type,Fulfillment,Refill,Datetime_Value,Actor_Id,Actor_Role,CCRDataObjectID from Medications', [], Medicationslist, errorCB);
}
function ImmunizationsDB(tx) {
    tx.executeSql('select Description,Type,Productname,Manufacturer,Route,Site,Datetime_Type,Datetime_Value,Actor_Id,Actor_Role,CCRDataObjectID from Immunizations', [], Immunizationslist, errorCB);
}
function ResultsDB(tx) {
    tx.executeSql('select Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type,Actor_Id,Actor_Role,Datetime_Value,CCRDataObjectID from Results', [], Resultslist, errorCB);
}
function VitalSignsDB(tx) {
    tx.executeSql('select Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type,Actor_Id,Actor_Role,Datetime_Value,CCRDataObjectID from VitalSigns', [], VitalSignslist, errorCB);
}
function ProceduresDB(tx) {
    tx.executeSql('select Description,Datetime_Value,Practitioner,Actor_Id,Actor_Role,CCRDataObjectID from Procedures', [], Procedureslist, errorCB);
}
function DialysisProceduresDB(tx) {
    tx.executeSql('select * from dialysis_Procedures', [], DialysisProcedureslist, errorCB);
}
function EncountersDB(tx) {
    tx.executeSql('select Type,Description,Datetime_Value,Location,Consent,Actor_Id,Actor_Role,CCRDataObjectID from Encounters', [], Encounterslist, errorCB);
}

function Agent_ResultsDB(tx) {
    tx.executeSql('select Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type,Actor_Id,Actor_Role,Datetime_Value from Agent_Results', [], AgentResultslist, errorCB);
}

function Agent_FunctionalStatusDB(tx) {
    tx.executeSql('select Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type xx,Actor_Id,Actor_Role,Datetime_Value,Problem_Desc from Agent_FunctionalStatus', [], AgentFunctionalStatulist, errorCB);
}

function Agent_FunctionalStatusDBlifelog(tx) {
    tx.executeSql('select Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type xx,Actor_Id,Actor_Role,Datetime_Value,Problem_Desc from Agent_FunctionalStatus', [], AgentFunctionalStatulistlifelog, errorCB);
}
function Agent_FunctionalStatusDBlifelog_newccrview(tx) {
    tx.executeSql('select Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type xx,Actor_Id,Actor_Role,Datetime_Value,Problem_Desc from Agent_FunctionalStatus', [], AgentFunctionalStatulistlifelog_newccrview, errorCB);
}

function ccrlist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        ccr_updatedate = results.rows.item(i).updatedate;
        console.log("ccr_updatedate " + ccr_updatedate);
        
    }
   
    $("#ccrupdatetimem").html("<li>강의내과</li><li>최근업데이트일 : "+ccr_updatedate+"</li>");
    $("#ccrupdatetimem").listview("refresh");
    
    console.log("ccr_updatedate refresh " + ccr_updatedate);
}


function AdvanceDirectiveslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {        
        var array =  new Array();
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        AdvanceDirectivesMap.put(i,array);
    }    
   /*
    for(y=0; y < AdvanceDirectivesMap.size(); y++){
        console.log("dbconnection.js >>AdvanceDirectives Map "+ AdvanceDirectivesMap.get(y) );
    }
    */
    
    
    
}
function Payerslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        var array =  new Array();
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Question_Name);
        array.push(results.rows.item(i).Question_Co);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Subscriber);
        array.push(results.rows.item(i).PaymentProvider);
        array.push(results.rows.item(i).Question_No);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        PayersMap.put(i,array);
    }
    /*
    for(y=0; y < PayersMap.size(); y++){
        console.log("dbconnection.js >>Payers Map "+ PayersMap.get(y) );
    }
    */
}
function FunctionalStatuslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
       
        var array =  new Array();
        array.push(results.rows.item(i).Problem_Desc);        
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Testresult_Value);
        array.push(results.rows.item(i).Testresult_Unit);
        array.push(results.rows.item(i).Problem_Actorid);
        array.push(results.rows.item(i).Problem_Actorrole);
        array.push(results.rows.item(i).Datetime_type);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).CCRDataObjectID);
        FunctionalStatusMap.put(i,array);
         
    }
   /*
     for(y=0; y < FunctionalStatusMap.size(); y++){
         console.log("dbconnection.js >>FunctionalStatus Map "+ FunctionalStatusMap.get(y) );
     }
    */
}
function Problemslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).CCRDataObjectID);
        ProblemsMap.put(i,array);
        
    }
    /*
     for(y=0; y < ProblemsMap.size(); y++){
     console.log("dbconnection.js >>Problems Map "+ ProblemsMap.get(y) );
     }
     */
}
function FamilyHistorylist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Exactdatetime);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Familymember_Actorrole);
        array.push(results.rows.item(i).Familymember_Actorid);
        array.push(results.rows.item(i).Healthstatus);
        array.push(results.rows.item(i).Problem_Desc);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        FamilyHistoryMap.put(i,array);
        
    }
    /*
    for(y=0; y < FamilyHistoryMap.size(); y++){
        console.log("dbconnection.js >>FamilyHistory Map "+ FamilyHistoryMap.get(y) );
    }
   */
}
function SocialHistorylist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        SocialHistoryMap.put(i,array);
        
    }
    /*
     for(y=0; y < SocialHistoryMap.size(); y++){
     console.log("dbconnection.js >>SocialHistory Map "+ SocialHistoryMap.get(y) );
     }
     */
}
function Alertslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        AlertsMap.put(i,array);
        
    }
    /*
    for(y=0; y < AlertsMap.size(); y++){
        console.log("dbconnection.js >>Alerts Map "+ AlertsMap.get(y) );
    }
   */
}
function Medicationslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Productname);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Status);
        array.push(results.rows.item(i).Route);
        array.push(results.rows.item(i).Frequency);
        array.push(results.rows.item(i).Quantity);
        array.push(results.rows.item(i).Manufacturer);
        array.push(results.rows.item(i).Instruction);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Fulfillment);
        array.push(results.rows.item(i).Refill);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        MedicationsMap.put(i,array);
        
    }
    /*
    for(y=0; y < MedicationsMap.size(); y++){
        console.log("dbconnection.js >>Medications Map "+ MedicationsMap.get(y) );
    }
    */
}
function Immunizationslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Productname);
        array.push(results.rows.item(i).Manufacturer);
        array.push(results.rows.item(i).Route);
        array.push(results.rows.item(i).Site);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        ImmunizationsMap.put(i,array);
        
    }
    /*
    for(y=0; y < ImmunizationsMap.size(); y++){
        console.log("dbconnection.js >>Immunizations Map "+ ImmunizationsMap.get(y) );
    }
    */
}
function Resultslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Testresult_Value);
        array.push(results.rows.item(i).Testresult_Unit);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).CCRDataObjectID);
        ResultsMap.put(i,array);
        
    }
    /*
    for(y=0; y < ResultsMap.size(); y++){
        console.log("dbconnection.js >>Results Map "+ ResultsMap.get(y) );
    }
    */
}
function VitalSignslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Testresult_Value);
        array.push(results.rows.item(i).Testresult_Unit);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).CCRDataObjectID);
        VitalSignsMap.put(i,array);
        
    }
    /*
    for(y=0; y < VitalSignsMap.size(); y++){
        console.log("dbconnection.js >>VitalSigns Map "+ VitalSignsMap.get(y)[0]);
    }
     */
}
function Procedureslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Practitioner);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        
        ProceduresMap.put(i,array);
        
    }
    /*
    for(y=0; y < ProceduresMap.size(); y++){
        console.log("dbconnection.js >>Procedures Map "+ ProceduresMap.get(y) );
    }
   */
}


function DialysisProcedureslist(tx, results) {
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        
        array.push(results.rows.item(i).DE10000);
        array.push(results.rows.item(i).DE10001);
        array.push(results.rows.item(i).DE10002);
        array.push(results.rows.item(i).DE10003);
        array.push(results.rows.item(i).DE10004);
        array.push(results.rows.item(i).DE10005);
        array.push(results.rows.item(i).DE10006);
        array.push(results.rows.item(i).DE10007);
        array.push(results.rows.item(i).DE10008);
        array.push(results.rows.item(i).DE10009);
        array.push(results.rows.item(i).DE10010);
        array.push(results.rows.item(i).DE10011);
        array.push(results.rows.item(i).DE10012);
        array.push(results.rows.item(i).DE10013);
        array.push(results.rows.item(i).DE10014);
        array.push(results.rows.item(i).DE10015);
        array.push(results.rows.item(i).DE10016);
        array.push(results.rows.item(i).DE10017);
        array.push(results.rows.item(i).DE10018);
        array.push(results.rows.item(i).DE10019);
        array.push(results.rows.item(i).DE10020);
        array.push(results.rows.item(i).DE10021);
        array.push(results.rows.item(i).DE10022);
        array.push(results.rows.item(i).DE10023);
        array.push(results.rows.item(i).DE10024);
        array.push(results.rows.item(i).DE10025);
        array.push(results.rows.item(i).DE10026);
        array.push(results.rows.item(i).DE10027);
        array.push(results.rows.item(i).DE10028);
        array.push(results.rows.item(i).DE10029);
        array.push(results.rows.item(i).DE10030);
        array.push(results.rows.item(i).DE10031);
        array.push(results.rows.item(i).DE10032);
        array.push(results.rows.item(i).DE10033);
        array.push(results.rows.item(i).DE10034);
        array.push(results.rows.item(i).DE10035);
        array.push(results.rows.item(i).DE10036);
        array.push(results.rows.item(i).DE10037);
        array.push(results.rows.item(i).DE10038);
        array.push(results.rows.item(i).DE10039);
        array.push(results.rows.item(i).DE10040);
        array.push(results.rows.item(i).DE10041);
        array.push(results.rows.item(i).DE10042);
        array.push(results.rows.item(i).DE10043);
        array.push(results.rows.item(i).DE10044);
        array.push(results.rows.item(i).DE10045);
        array.push(results.rows.item(i).DE10046);
        array.push(results.rows.item(i).DE10047);
       
        DialysisProceduresMap.put(i,array);
        
    }
    for(y=0; y < DialysisProceduresMap.size(); y++){
     console.log("dbconnection.js >>DialysisProceduresMap "+ DialysisProceduresMap.get(y) );
     }
    
}


function Encounterslist(tx, results) {
   
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Datetime_Value);
        array.push(results.rows.item(i).Location);
        array.push(results.rows.item(i).Consent);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).CCRDataObjectID);
        EncountersMap.put(i,array);
        
    }
    /*
    for(y=0; y < EncountersMap.size(); y++){
        console.log("dbconnection.js >>Encounters Map "+ EncountersMap.get(y) );
    }
   */
}



function selectCCR(){
    
    console.log("dbconnection.js >>--------------- selectCCR() 1");
    
     db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    
     console.log("dbconnection.js >>--------------- selectCCR() 2");
    
     db.transaction(AdvanceDirectivesDB, errorCB, successCB);
     db.transaction(PayersDB, errorCB, successCB);
     db.transaction(FunctionalStatusDB, errorCB, successCB);    
     db.transaction(ProblemsDB, errorCB, successCB);
     db.transaction(FamilyHistoryDB, errorCB, successCB);
     db.transaction(SocialHistoryDB, errorCB, successCB);
     db.transaction(AlertsDB, errorCB, successCB);
     db.transaction(MedicationsDB, errorCB, successCB);
     db.transaction(ImmunizationsDB, errorCB, successCB);
     db.transaction(ResultsDB, errorCB, successCB);
     db.transaction(VitalSignsDB, errorCB, successCB);
     db.transaction(ProceduresDB, errorCB, successCB);
     db.transaction(EncountersDB, errorCB, successCB);
    
    db.transaction(DialysisProceduresDB, errorCB, successCB);
    
     console.log("dbconnection.js >>--------------- selectCCR() 3");
    
     db.transaction(Agent_ResultsDB, errorCB, successCB);
    
    selectAgentFunctionalStatus();
     console.log("dbconnection.js >>--------------- selectCCR() 4");
    
}


function selectAgentResults(){
    db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    db.transaction(Agent_ResultsDB, errorCB, successCB);
    console.log("dbconnection.js >>--------------- Agent_ResultsDB");
   // openDb();
}

function selectAgentFunctionalStatus(){
    db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    db.transaction(Agent_FunctionalStatusDB, errorCB, successCB);
    console.log("dbconnection.js >>--------------- Agent_FunctionalStatusDB");
    // openDb();
}

function selectAgentFunctionalStatuslifelog(){
    db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    db.transaction(Agent_FunctionalStatusDBlifelog, errorCB, successCB);
    console.log("dbconnection.js >>--------------- selectAgentFunctionalStatuslifelog");
    // openDb();
}


function selectAgentFunctionalStatuslifelog_newccrview(){
    db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    db.transaction(Agent_FunctionalStatusDBlifelog_newccrview, errorCB, successCB);
    console.log("dbconnection.js >>--------------- selectAgentFunctionalStatuslifelog");
    // openDb();
}

function AgentResultslist(tx, results) {
    
      AgentResultsMap.clear();
    
        
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Testresult_Value);
        array.push(results.rows.item(i).Testresult_Unit);
        array.push(results.rows.item(i).Datetime_Type);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        
        AgentResultsMap.put(i,array);
        
    }
   }



function AgentFunctionalStatulist(tx, results) {
    
    AgentFunctionalStatusMap2.clear();
    
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);//0
        array.push(results.rows.item(i).Type);//1
        array.push(results.rows.item(i).Testresult_Value);//2
        array.push(results.rows.item(i).Testresult_Unit);//3
        array.push(results.rows.item(i).xx);//4
        array.push(results.rows.item(i).Actor_Id);//5
        array.push(results.rows.item(i).Actor_Role);//6
        array.push(results.rows.item(i).Datetime_Value);//7
        
        //console.log("dbconnection.js >>AgentFunctionalStatusMap2 >>>>>>>>> Datetime_Type "+ results.rows.item(i).xx);
        //console.log("dbconnection.js >>AgentFunctionalStatusMap2 >>>>>>>>> Datetime_Value "+ results.rows.item(i).Datetime_Value);

        
        
        AgentFunctionalStatusMap2.put(i,array);
        
    }
    /*
    var cont = "";
    for(y=0; y < AgentFunctionalStatusMap.size(); y++){
        console.log("dbconnection.js >>AgentFunctionalStatusMap Map "+ AgentFunctionalStatusMap.get(y) );
        cont += AgentFunctionalStatusMap.get(y) + "<br>";
        
    }
    
    
    
    var colum = new Array();
    
    var html = new Array();
    
    for(var i = 0 ; i < 11; i++){
        colum[i]=new Array();
    }
    
    for(var i = 0 ; i < AgentFunctionalStatusMap.size(); i++){
        
        colum[0][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[0])+tdHtmlE;//1912 내용
        colum[1][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[1])+tdHtmlE;//1913 유형
        colum[2][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[2])+tdHtmlE; //1916 검사결과
        colum[3][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[3])+tdHtmlE; //1917 단위
        colum[4][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[4])+tdHtmlE; //1920 날짜유형
        colum[5][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[5])+tdHtmlE;//2276 출처 기록자
        colum[6][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[6])+tdHtmlE;//2277 출처 기관
        colum[7][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[7])+tdHtmlE; //1407 일시
    }
    
    for(var i = 0 ; i < AgentFunctionalStatusMap.size(); i++){
        html[i] = "<tr>"+colum[0][i]+colum[1][i]+colum[2][i]+colum[3][i]+colum[4][i]+colum[5][i]+colum[6][i]+colum[7][i]+"</tr>";
        
    }
    
    var ht = "<table id='results9' style='width:320px;' >"+
     "<tr>"+
     "<th width='80'>내용</th>"+
     "<th width='80'>검사유형</th>"+
     "<th width='80'>검사결과</th>"+
     "<th width='80'>단위</th>"+
     "<th width='80'>날짜유형</th>"+
     "<th width='80'>출처 기록자</th>"+
     "<th width='80'>출처 기관</th>"+
     "<th width='80'>일시</th>"+
     "</tr>"+
     "</table>;"

    $("#rs002").html(ht);
    
    
    for(var i = 0 ; i< AgentFunctionalStatusMap.size();i++){
        $("#results9").append(html[i]);
    }
    
    //contentsScroll('rs002');
    var contscroll = new iScroll('rs002');
*/
}


function AgentFunctionalStatulistlifelog_newccrview(tx, results) {
    
    AgentFunctionalStatusMap.clear();
    
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Testresult_Value);
        array.push(results.rows.item(i).Testresult_Unit);
        array.push(results.rows.item(i).xx);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        
        console.log("dbconnection.js >>life log *********** AgentFunctionalStatusMap >>>>>>>>> Datetime_Type "+ results.rows.item(i).xx);
        console.log("dbconnection.js >>AgentFunctionalStatusMap >>>>>>>>> Datetime_Value "+ results.rows.item(i).Datetime_Value);
        
        
        
        AgentFunctionalStatusMap.put(i,array);
        
    }
    
}

function AgentFunctionalStatulistlifelog(tx, results) {
    
    AgentFunctionalStatusMap.clear();
    
    
    for (var i=0; i<results.rows.length; i++) {
        
        var array =  new Array();
        array.push(results.rows.item(i).Description);
        array.push(results.rows.item(i).Type);
        array.push(results.rows.item(i).Testresult_Value);
        array.push(results.rows.item(i).Testresult_Unit);
        array.push(results.rows.item(i).xx);
        array.push(results.rows.item(i).Actor_Id);
        array.push(results.rows.item(i).Actor_Role);
        array.push(results.rows.item(i).Datetime_Value);
        
        console.log("dbconnection.js >>life log *********** AgentFunctionalStatusMap >>>>>>>>> Datetime_Type "+ results.rows.item(i).xx);
        console.log("dbconnection.js >>AgentFunctionalStatusMap >>>>>>>>> Datetime_Value "+ results.rows.item(i).Datetime_Value);
        
        
        
        AgentFunctionalStatusMap.put(i,array);
        
    }
    
    var cont = "";
    for(y=0; y < AgentFunctionalStatusMap.size(); y++){
        console.log("dbconnection.js >>AgentFunctionalStatusMap Map "+ AgentFunctionalStatusMap.get(y) );
        cont += AgentFunctionalStatusMap.get(y) + "<br>";
        
    }
    
    
    
    var colum = new Array();
    
    var html = new Array();
    
    for(var i = 0 ; i < 11; i++){
        colum[i]=new Array();
    }
    
    for(var i = 0 ; i < AgentFunctionalStatusMap.size(); i++){
        
        colum[0][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[0])+tdHtmlE;//1912 내용
        colum[1][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[1])+tdHtmlE;//1913 유형
        colum[2][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[2])+tdHtmlE; //1916 검사결과
        colum[3][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[3])+tdHtmlE; //1917 단위
        colum[4][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[4])+tdHtmlE; //1920 날짜유형
        colum[5][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[5])+tdHtmlE;//2276 출처 기록자
        colum[6][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[6])+tdHtmlE;//2277 출처 기관
        colum[7][i]=tdHtmlS+nullCheck(AgentFunctionalStatusMap.get(i)[7])+tdHtmlE; //1407 일시
    }
    
    for(var i = 0 ; i < AgentFunctionalStatusMap.size(); i++){
        html[i] = "<tr>"+colum[0][i]+colum[1][i]+colum[2][i]+colum[3][i]+colum[4][i]+colum[5][i]+colum[6][i]+colum[7][i]+"</tr>";
        
    }
    
    var ht = "<table id='results9x' style='width:320px;' >"+
    "<tr>"+
    "<th width='80'>내용</th>"+
    "<th width='80'>검사유형</th>"+
    "<th width='80'>검사결과</th>"+
    "<th width='80'>단위</th>"+
    "<th width='80'>날짜유형</th>"+
    "<th width='80'>출처 기록자</th>"+
    "<th width='80'>출처 기관</th>"+
    "<th width='80'>일시</th>"+
    "</tr>"+
    "</table>;"
    
    $("#lifers003").html(ht);
    
    
    for(var i = 0 ; i< AgentFunctionalStatusMap.size();i++){
        $("#results9x").append(html[i]);
    }
    
    //contentsScroll('rs002');
    var contscroll = new iScroll('lifers003');
    
}





function Warfarin(agent_id,str){
    console.log("dbconnection.js >>## WebSocket -warfarin ## request <<<<< " + str);
    var t = str.substring(str.indexOf("/")+1,str.length);
    //console.log("dbconnection.js >>## WebSocket -warfarin ## "+t);
    selectusrDB(agent_id,t);
}

function selectusrDB(agent_id,rsid) {
    var tmpGenotype=0;
    db = window.openDatabase("Database", "1.0", "healthavatar", 20000000);
    var query = "select genotype from usrDB where rsid = '" + rsid + "'";
    db.transaction(function (trxn) {
                   trxn.executeSql(query,[],
                                   function (transaction, resultSet) {
                                   //console.log('## WebSocket -warfarin ## select success');
                                   
                                   //console.log("dbconnection.js >>## WebSocket -warfarin ## " + resultSet.rows.item(0).genotype);
                                   tmpGenotype = resultSet.rows.item(0).genotype;
                                   tmpGenotype = tmpGenotype.trim();
                                   var s = '{"genomic":"'+tmpGenotype+'"}';
                                   send_message(agent_id+"/"+s);
                                   console.log("dbconnection.js >>## WebSocket -warfarin ## send_message >>>>> " + agent_id+"/"+s);
                                   },
                                   function (transaction, error) {
                                   console.log('## WebSocket -warfarin ## select fail' + error);
                                   }
                                   );
                   });
    
}





